package com.example.demo.service.Impl;

import com.example.demo.common.domain.LeaveRecordPlus;
import com.example.demo.common.domain.Leave_Record;
import com.example.demo.common.domain.Leave_RecordExample;
import com.example.demo.mapper.Leave_RecordMapper;
import com.example.demo.mapper.RecordMapper;
import com.example.demo.service.LeaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("leaveServiceImpl")
public class LeaveServiceImpl implements LeaveService {
    @Autowired
    Leave_RecordMapper leave_recordMapper;


    @Override
    public void insertSelective(Leave_Record record) {
        leave_recordMapper.insertSelective(record);
    }

    @Override
    public List<Leave_Record> selectAll() {
        Leave_RecordExample example = new Leave_RecordExample();
        example.createCriteria();
        return leave_recordMapper.selectByExample(example);
    }



    @Override
    public Leave_Record selectByPrimaryId(Integer lid) {
        Leave_RecordExample example = new Leave_RecordExample();
        example.createCriteria().andLidEqualTo(lid);
        List<Leave_Record> leave_records = leave_recordMapper.selectByExample(example);
        return leave_records.size() == 0?null:leave_records.get(0);
    }

    @Override
    public void updateGIdByPrimaryId(Integer lid, Integer gid) {
        Leave_Record l = leave_recordMapper.selectByPrimaryKey(lid);
        l.setGid(gid);
        l.setGeneralagree(1);
        leave_recordMapper.updateByPrimaryKey(l);
    }

    @Override
    public void updateDIdByPrimaryId(Integer lid, Integer did) {
        Leave_Record l = leave_recordMapper.selectByPrimaryKey(lid);
        System.out.println(l);
        l.setDid(did);
        l.setDeputyagree(1);
        leave_recordMapper.updateByPrimaryKeySelective(l);
    }

    @Override
    public void updateDivIdByPrimaryId(Integer lid, Integer divid) {
        Leave_Record l = leave_recordMapper.selectByPrimaryKey(lid);
        System.out.println(l);
        l.setDivid(divid);
        l.setDividagree(1);
        leave_recordMapper.updateByPrimaryKey(l);
    }

    @Override
    public List<LeaveRecordPlus> selectAllPlus() {
        return leave_recordMapper.seletAllPlus();
    }
    @Override
    public List<LeaveRecordPlus> GeneralSelectAllLeave() {
        return leave_recordMapper.GeneralSelectAllLeave();
    }

    @Override
    public List<LeaveRecordPlus> DeputySelectAllLeave() {
        return leave_recordMapper.DeputySelectAllLeave();
    }
}
